package com.ccjq.jq173.shosestore.web.controller.member;

import com.ccjq.jq173.shosestore.member.service.UserService;
import com.ccjq.jq173.shosestore.member.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class UserExistCheckServlet extends HttpServlet {
    private UserService userService;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("===========  执行用户名唯一性校验  ============");
        String username=request.getParameter("username");
        userService =new UserServiceImpl();
        int result = userService.isExists(username);
        String str="{\"code\":200,\"result\":"+result+"}";

        PrintWriter out=response.getWriter();
        out.write(str);
        out.flush();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
